import request from '@/api/request'
import g from "@/utils/utilFn";
export function getlist(param) {
    param = g.objEngraving({
        name: '',
        department: "",
        group: "",
        jurisdiction: '',
        pid: '',
        page: 1,
        limit: 10,
        filed: "id",
        sort: "ascending",
    }, param || {})
    let data = new FormData()
    Object.keys(param).map((key) => {
        data.append(key, param[key] || "");
    });
    return request({
        url: '/org_teamMember/getlist',
        method: 'POST',
        data
    })
}

export function remove_by_id(id) {
    let data = new FormData()
    data.append("id", id || "");
    return request({
        url: '/org_teamMember/delete_by_id',
        method: 'POST',
        data
    })
}

export function update(param) {
    param = g.objEngraving({
        id: "",
        name: "",
        department: "",
        group: "",
        jurisdiction: "",
        pid: "",
        equipment: ""
    }, param || {})
    param.equipment = param.equipment.join(',')
    let data = new FormData()
    Object.keys(param).map((key) => {
        data.append(key, param[key] || "");
    });
    return request({
        url: '/org_teamMember/update',
        method: 'POST',
        data
    })
}
export function notExistAdd(param) {
    param = g.objEngraving({
        id: "",
        name: "",
        department: "",
        group: "",
        jurisdiction: "",
        pid: "",
        equipment: ""
    }, param || {})
    param.equipment = param.equipment.join(',')
    let data = new FormData()
    Object.keys(param).map((key) => {
        data.append(key, param[key] || "");
    });
    return request({
        url: '/org_teamMember/notExistAdd',
        method: 'POST',
        data
    })
}


export function bindAccount(param) {
    param = g.objEngraving({
        id: "",
        bind_account: ""
    }, param || {})
    let data = new FormData()
    Object.keys(param).map((key) => {
        data.append(key, param[key] || "");
    });
    return request({
        url: '/org_teamMember/bindAccount',
        method: 'POST',
        data
    })
}
export function getBoss() {
    let myPromise = new Promise((resolve, reject) => {
        var resp = sessionStorage.getItem("org_teamMember_getBoss")
        if (resp) {
            resolve(JSON.parse(resp))
        } else {
            request({
                url: '/org_teamMember/getBoss',
                method: 'POST'
            }).then((resp1) => {
                sessionStorage.setItem("org_teamMember_getBoss", JSON.stringify(resp1))
                resolve(resp1)
            })
        }
    });
    return myPromise

}
export function getDepartment() {
    let myPromise = new Promise((resolve, reject) => {
        var resp = sessionStorage.getItem("org_department_getListAll")
        if (resp) {
            resolve(JSON.parse(resp))
        } else {
            request({
                url: '/org_department/getListAll',
                method: 'POST'
            }).then((resp1) => {
                sessionStorage.setItem("org_department_getListAll", JSON.stringify(resp1))
                resolve(resp1)
            })
        }
    });
    return myPromise
}


export function getDevice() {
    let myPromise = new Promise((resolve, reject) => {
        var resp = sessionStorage.getItem("org_device_getListAll")
        if (resp) {
            resolve(JSON.parse(resp))
        } else {
            request({
                url: '/org_device/getListAll',
                method: 'POST'
            }).then((resp1) => {
                sessionStorage.setItem("org_device_getListAll", JSON.stringify(resp1))
                resolve(resp1)
            })
        }
    });
    return myPromise
}

export const jobArray = [
    { id: 1, key: '主管', name: '主管' },
    { id: 2, key: '组长', name: '组长' },
    { id: 3, key: '组员', name: '组员' }
]